package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Cpzlbz;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class CpzlbzForm extends BasePage implements Serializable {
    private GenericManager<Cpzlbz, Long> cpzlbzManager;
    private Cpzlbz cpzlbz = new Cpzlbz();
    private Long id;

    public void setCpzlbzManager(GenericManager<Cpzlbz, Long> cpzlbzManager) {
        this.cpzlbzManager = cpzlbzManager;
    }

    public Cpzlbz getCpzlbz() {
        return cpzlbz;
    }

    public void setCpzlbz(Cpzlbz cpzlbz) {
        this.cpzlbz = cpzlbz;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        cpzlbzManager.remove(cpzlbz.getId());
        addMessage("cpzlbz.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            cpzlbz = cpzlbzManager.get(id);
        } else {
            cpzlbz = new Cpzlbz();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (cpzlbz.getId() == null || cpzlbz.getId() == 0);
        cpzlbzManager.save(cpzlbz);

        String key = (isNew) ? "cpzlbz.added" : "cpzlbz.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 